<?php

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;

class Admin extends BaseModel
{
    use SoftDeletes;

    public $table = 'admin';
    public $timestamps = 'true';

    // 家访
    const HOME_VISIT_WHETHER_YES = 1; // 参与家访
    const HOME_VISIT_WHETHER_NON = 2; // 没有家访

    //正常登录
    public const STATUS_NORMAL = 1;
    //禁止登录
    public const STATUS_DISABLE = 2;
    //已离职
    public const STATUS_LEAVE_OFFICE = 3;
    //测试
    public const STATUS_LEAVE_TEST = 4;

    //男性
    public const GENDER_MAN = 1;
    //女性
    public const GENDER_WOMAN = 2;

    // 角色ID
    const ADMIN_ROOT_ID = 1; // 超级管理员
    const COOUNTY_PROJECT_OFFICE_ID = 7; // 县项目办
    const COUNTY_SUPERVISOR_ID = 8; // 县总督导员
    const COUNTY_SUPERVISOR_ASSISTANT_ID = 9; // 县级督导员助理
    const TOWN_SUPERVISOR_ID = 10; // 乡镇督导员
    const TOWN_SUPERVISOR_GROUP_LEADER_ID = 11; // 乡镇督导员组长
    const CHILD_CARE_COUNSELOR_ID = 12; // 婴幼儿养育指导师

    /**
     * 允许变更的属性
     * @var array
     */
    public static $fieldsStatic = [
          'role_id',
          'parent_id',
          'profession',
          'phone',
          'password',
          'username',
          'identity_id',
          'birthday',
          'avatar',
          'gender',
          'province',
          'city',
          'area',
          'town',
          'village',
          'nation_id',
          'education',
          'major',
          'graduated_school',
          'graduated_date',
          'marriage',
          'family_province',
          'family_city',
          'family_area',
          'family_address',
          'population_number',
          'children_number',
          'team_id',
          'status',
          'entry_time',
          'departure_time',
          'care_counselor',
          'updated_at',
          'deleted_at',
    ];


    /**
     * 婚姻状态
     */
    public static function getMarriageStatus($marriageId = 0)
    {
        $marriage = [
            "2001" => '已婚',
            "2002" => '未婚',
            "2003" => '丧偶',
            "2004" => '离婚',
            "2005" => '再婚',
        ];

        if ($marriageId) {
            return $marriage[$marriageId] ?? "未知";
        }

        return $marriage;
    }

    /**
     * 性别
     */
    public static function getGenderStatus($genderId = 0)
    {
        $genders = [
            "0" => "未知",
            "1" => '男',
            "2" => '女',
        ];

        if ($genderId) {
            return $genders[$genderId] ?? "未知";
        }

        return $genders;
    }

    /**
     * 学历
     */
    public static function getEducation($educationId = 0)
    {
        $education = [
            "3001" => '小学',
            "3002" => '初中',
            "3003" => '中专',
            "3004" => '职高',
            "3005" => '高中',
            "3006" => '专科',
            "3007" => '本科',
            "3008" => '硕士研究生',
            "3009" => '博士研究生',
        ];

        if ($educationId) {
            return $education[$educationId] ?? "未知";
        }
        return $education;
    }

    /**
     * 1:正常 2 禁用 3 离职
     */
    public static function getStatus($statusId = 0)
    {
        $statuses = [
            "1" => '正常',
            "2" => '禁用',
            "3" => '离职',
            "4" => '测试',
        ];

        if ($statusId) {
            return $statuses[$statusId] ?? "未知";
        }

        return $statuses;
    }

    /**
     * 人员孩子
     * @Author   thomashtao
     * @DateTime 2021-08-10T22:09:05+0800
     */
    public function AdminChildren(){
        return $this->hasMany(AdminChildren::class, 'admin_id', 'id');
    }

    /**
     * 执行人员角色
     */
    public function AdminRole()
    {
        return $this->hasMany(Role::class, 'id', 'role_id')->select("id","name","slug","description","login_platform");
    }

    /**
     *  执行人员上级
     */
    public function AdminRoleParent()
    {
        return $this->hasOne(Admin::class, 'id', 'parent_id')->select("id","role_id","parent_id","username","avatar");
    }

    /**
     * 民族
     */
    public function nation()
    {
        return $this->hasOne(Nation::class, 'id', 'nation_id')->select("id",'nation_name');
    }

    /**
     * 用户菜单
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function roleMenuInfo(): \Illuminate\Database\Eloquent\Relations\HasMany
    {
        return $this->hasMany(RoleMenu::class, 'role_id', 'role_id');
    }

    /**
     * 婴幼儿养育指导师，管辖的村
     */
    public function Village()
    {
        return $this->hasMany(AdminTeam::class, 'admin_id', 'id');
    }

    /**
     * 省
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function addressProvince()
    {
        return $this->hasOne(Area::class, 'id', 'province')->select("id",'name');
    }

    /**
     * 城市
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function addressCity()
    {
        return $this->hasOne(Area::class, 'id', 'city')->select("id",'name');
    }

    /**
     * 区县
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function addressArea()
    {
        return $this->hasOne(Area::class, 'id', 'area')->select("id",'name');
    }

    /**
     * 乡镇
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function addressTown()
    {
        return $this->hasOne(Area::class, 'id', 'town')->select("id",'name');
    }


}
